(function()
{
	
	var dlg;
	
	CKEDITOR.dialog.add( 'flvPlayer', function( editor )
	{
		return {
			title : editor.lang.flash.title,
			minWidth : 600,
			minHeight : 480,
			onShow : function()
			{
				dlg = this;
				// do nothing
			},
			onOk : function()
			{

				var paramMap = null,
					scriptHtml = '',
					colorsHtml = '',
					optionalHtml = '',
					uuId = (new Date).getTime();
					
				if (this.getValueOf('info', 'backcolor') != '')
					colorsHtml += 's1.addVariable("backcolor","' + this.getValueOf('info', 'backcolor') + '");\n';
				if (this.getValueOf('info', 'frontcolor') != '')
					colorsHtml += 's1.addVariable("frontcolor","' + this.getValueOf('info', 'frontcolor') + '");\n';
				if (this.getValueOf('info', 'lightcolor') != '')
					colorsHtml += 's1.addVariable("lightcolor","' + this.getValueOf('info', 'lightcolor') + '");\n';
				if (this.getValueOf('info', 'screencolor') != '')
					colorsHtml += 's1.addVariable("screencolor","' + this.getValueOf('info', 'screencolor') + '");\n';


				if (this.getValueOf('info', 'type') == 'single') {
					optionalHtml += 's1.addVariable("image","' + this.getValueOf('info', 'image') + '");\n';
				} else {
					optionalHtml += 's1.addVariable("autoscroll","true");\n';
					optionalHtml += 's1.addVariable("allowscriptaccess","always");\n';
					optionalHtml += 's1.addVariable("displaywidth","' + this.getValueOf('info', 'displaywidth') + '");\n';
					optionalHtml += 's1.addVariable("thumbsinplaylist","' + this.getValueOf('info', 'thumbsinplaylist') + '");\n';
					optionalHtml += 's1.addVariable("shuffle","false");\n';
				}

				scriptHtml =
					'<script src="' + CKEDITOR.basePath + '/plugins/flvPlayer/swfobject.js" type="text/javascript"></script>\n' +
					'<table align="left" class="svFlvPlayer">\n' +
						'<tbody>\n' +
							'<tr>\n' +
								'<td>\n' +
									'<p id="player' + uuId + '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>\n' +
								'</td>\n' +
							'</tr>\n' +
						'</tbody>\n' +
					'</table>\n' +
					'<script type="text/javascript">\n' +
					'<!--\n' +
						'var s1 = new SWFObject("' + CKEDITOR.basePath + 'plugins/flvPlayer/mediaplayer.swf","' + this.getValueOf('info', 'type') + '","' + this.getValueOf('info', 'width') + '","' +this.getValueOf('info', 'height') + '","7");\n' +
						's1.addVariable("width","' + this.getValueOf('info', 'width') + '");\n' +
						's1.addVariable("height","' + this.getValueOf('info', 'height') + '");\n' +
						's1.addVariable("autostart","' + this.getValueOf('info', 'autostart') + '");\n' +
						's1.addVariable("file","' + this.getValueOf('info', 'file') + '");\n' +
						's1.addVariable("repeat","' + this.getValueOf('info', 'repeat') + '");\n' +
						's1.addVariable("showdownload","' + this.getValueOf('info', 'showdownload') + '");\n' +
						's1.addVariable("link","' + this.getValueOf('info', 'file') + '");\n' +
						's1.addParam("allowfullscreen","' + this.getValueOf('info', 'allowfullscreen') + '");\n' +
						's1.addVariable("showdigits","' + this.getValueOf('info', 'showdigits') + '");\n' +
						's1.addVariable("shownavigation","' + this.getValueOf('info', 'shownavigation') + '");\n' +
						's1.addVariable("logo","' + this.getValueOf('info', 'logo') + '");\n' +
						's1.addVariable("recommendations","' + this.getValueOf('info', 'recommendations') + '");\n' +
						colorsHtml + optionalHtml +
						's1.write("player' + uuId + '");\n' +
					'//-->\n' +
					'</script>';


				editor.insertHtml(scriptHtml);
			},

			onHide : function()
			{
				// do nothing
			},

			contents : [
				{
					id : 'info',
					label : editor.lang.common.generalTab,
					accessKey : 'I',
					elements :
					[
					 
					 
					 	// File Type
					 	{
							type: 'fieldset',
							label: 'File Type',
							style: 'border: 1px solid #a0a0a0; padding: 10px;',
							children:
							[
								{
									id: 'type',
									type: 'radio',
									'default': 'single',
									items: [
										[ 'Single File', 'single' ],
										[ 'Playlist', 'list']
									],
									onChange : function()
									{
										if (this.getValue() == 'single') {
											this.getDialog().getContentElement('info', 'file').enable();
											this.getDialog().getContentElement('info', 'browse').getElement().show();
											this.getDialog().getContentElement('info', 'image').enable();
											this.getDialog().getContentElement('info', 'browseimg').getElement().show();
											this.getDialog().getContentElement('info', 'playlist').disable();
											this.getDialog().getContentElement('info', 'browseplaylist').getElement().hide();
											this.getDialog().getContentElement('info', 'displayplaylist').disable();
											this.getDialog().getContentElement('info', 'playlistdimension').disable();
											this.getDialog().getContentElement('info', 'thumbsinplaylist').disable();
										} else {
											this.getDialog().getContentElement('info', 'file').disable();
											this.getDialog().getContentElement('info', 'browse').getElement().hide();
											this.getDialog().getContentElement('info', 'image').disable();
											this.getDialog().getContentElement('info', 'browseimg').getElement().hide();
											this.getDialog().getContentElement('info', 'playlist').enable();
											this.getDialog().getContentElement('info', 'browseplaylist').getElement().show();
											this.getDialog().getContentElement('info', 'displayplaylist').enable();
											this.getDialog().getContentElement('info', 'playlistdimension').enable();
											this.getDialog().getContentElement('info', 'thumbsinplaylist').enable();
										}
									}
									
								}
							]
						},
						// End File Type
					 
					 
					 	// Movie Selection
					 	{
							type: 'hbox',
							widths : [ '280px', '110px' ],
							align : 'right',
							children:
							[
							 	
								{
									id : 'file',
									type : 'text',
									label : '.FLV Movie',
									required : true,
									validate : CKEDITOR.dialog.validate.notEmpty( 'Please select a .FLV movie.' )
								},
								{
									type : 'button',
									id : 'browse',
									filebrowser : 'info:file',
									hidden : true,
									// v-align with the 'src' field.
									// TODO: We need something better than a fixed size here.
									style : 'display:inline-block;margin-top:10px;',
									label : editor.lang.common.browseServer
								}

							]
									   
						},
						// End Movie
						
						
						// Preview Image
						{
							type: 'hbox',
							widths: [ '280px', '110px' ],
							align: 'right',
							children:
							[

								{
									id : 'image',
									type : 'text',
									label : 'Preview Image',
									required : false
								},
								{
									type : 'button',
									id : 'browseimg',
									filebrowser : {
										action : 'Browse',
										target: 'info:image',
										url: editor.config.filebrowserImageBrowseUrl
									},
									hidden : true,
									// v-align with the 'src' field.
									// TODO: We need something better than a fixed size here.
									style : 'display:inline-block;margin-top:10px;',
									label : editor.lang.common.browseServer
								}
							]
						},
						// End Preview Image

						// Playlist URL
						{
							type: 'hbox',
							widths: [ '280px', '110px' ],
							align: 'right',
							children:
							[

								{
									id : 'playlist',
									type : 'text',
									label : 'Playlist URL',
									required : false
								},
								{
									type : 'button',
									id : 'browseplaylist',
									filebrowser : 'info:playlist',
									hidden : true,
									// v-align with the 'src' field.
									// TODO: We need something better than a fixed size here.
									style : 'display:inline-block;margin-top:10px;',
									label : editor.lang.common.browseServer
								}
							]
						},
						// End Playlist URL
						
						// Movie Attributes and Player Attributes
						{
							type: 'hbox',
							widths: [ '280px', '280px'],
							align: 'right',
							children:
							[
							 
							 	// Movie Attributes
								{
									type: 'vbox',
									children:
									[
									 	// Watermark
									 	{
											type: 'hbox',
											widths: ['100px', '50px'],
											align: 'right',
											children: 
											[
										
												{
													id : 'logo',
													type : 'text',
													label : 'Watermark Image',
													required : false
												},
												{
													type : 'button',
													id : 'browsewmurl',
													filebrowser : {
														action : 'Browse',
														target: 'info:logo',
														url: editor.config.filebrowserImageBrowseUrl
													},
													hidden : false,
													// v-align with the 'src' field.
													// TODO: We need something better than a fixed size here.
													style : 'display:inline-block;margin-top:10px;',
													label : editor.lang.common.browseServer
												}
											]
										},
										// End Watermark

										// Recommendations List
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'recommendations',
													type : 'text',
													label : 'Recommendations List',
													required : false
												},
												{
													type : 'button',
													id : 'browserecurl',
													filebrowser : 'info:recommendations',
													hidden : false,
													// v-align with the 'src' field.
													// TODO: We need something better than a fixed size here.
													style : 'display:inline-block;margin-top:10px;',
													label : editor.lang.common.browseServer
												}
											]
										},
										// End Recommendations List
										
										
										// Autoplay
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'autostart',
													type : 'checkbox',
													label : 'Autoplay',
													required : false
												}
											]
										},

										// Loop
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'repeat',
													type : 'checkbox',
													label : 'Loop',
													required : false
												}
											]
										},

										// Downloadable
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'showdownload',
													type : 'checkbox',
													label : 'Downloadable',
													'default': 'checked',
													required : false
												}
											]
										},

										// Allow Fullscreen
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'allowfullscreen',
													type : 'checkbox',
													label : 'Allow Fullscreen',
													'default': 'checked',
													required : false
												}
											]
										},

										// Display Playlist
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'displayplaylist',
													type : 'select',
													label : 'Display Playlist',
													labelLayout: 'horizontal',
													'default' : '',
													style : 'width : 100%;',
													items :
													[
														[ 'Do Not Display' , 'none'],
														[ 'Display on Right', 'right' ],
														[ 'Display Below', 'below' ]
													]
												}
											]
										},
										// End Display Playlist

										// Playlist Dimension
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'playlistdimension',
													type : 'text',
													label : 'Playlist Dimension',
													labelLayout: 'horizontal'
												}
											]
										},
										
										// Display Thumbnails in Playlist
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'thumbsinplaylist',
													type : 'checkbox',
													label : 'Display Thumbnails in Playlist',
													required : false
												}
											]
										},


									]
								},
								// End Movie Attributes
								
								// Player Attributes
								{
									type: 'vbox',
									children:
									[
									 	// Width
									 	{
											type: 'hbox',
											widths: ['100px', '50px' ],
											align: 'right',
											children: 
											[
										
												{
													id : 'width',
													type : 'text',
													label : 'Movie Width (px)',
													labelLayout: 'horizontal',
													required : true,
													validate : CKEDITOR.dialog.validate.notEmpty( 'Please enter the movie width.' )
												}
											]
										},
										// End Width

										// Height
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'height',
													type : 'text',
													label : 'Movie Height (px)',
													labelLayout: 'horizontal',
													required : true,
													validate : CKEDITOR.dialog.validate.notEmpty( 'Please enter the movie height.' )
												}
											]
										},
										// End Height
										
										// Bg Color
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'backcolor',
													type : 'text',
													label : 'Bg Color',
													labelLayout: 'horizontal',
													required : false
												},
												{
													type : 'button',
													id : 'btnbackcolor',
													onLoad : function()
													{
														function onColorSelect(evt) {
															this.removeListener('ok', onColorSelect);
															dlg.setValueOf('info', 'backcolor', this.getContentElement('picker', 'selectedColor').getValue());
														}
														this.on('click', function(evt) {
															editor.openDialog('colordialog', function() {
																this.on ('ok', onColorSelect);
															});
														});
													},											
													hidden : false,
													label : 'Select...'
												}
											]
										},
										// End Bg Color										

										// Toolbar Color
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'screencolor',
													type : 'text',
													label : 'Toolbar Color',
													labelLayout: 'horizontal',
													required: false
												},
												{
													type : 'button',
													id : 'btnscreencolor',
													onLoad : function()
													{
														function onColorSelect(evt) {
															this.removeListener('ok', onColorSelect);
															dlg.setValueOf('info', 'screencolor', this.getContentElement('picker', 'selectedColor').getValue());
														}
														this.on('click', function(evt) {
															editor.openDialog('colordialog', function() {
																this.on ('ok', onColorSelect);
															});
														});													},											
													hidden : false,
													label : 'Select...'
												}

											]
										},
										// End Toolbar Color										

										// Toolbar Text Color
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'frontcolor',
													type : 'text',
													label : 'Toolbar Text Color',
													labelLayout: 'horizontal',
													required : false
												},
												{
													type : 'button',
													id : 'btnfrontcolor',
													onLoad : function()
													{
														function onColorSelect(evt) {
															this.removeListener('ok', onColorSelect);
															dlg.setValueOf('info', 'frontcolor', this.getContentElement('picker', 'selectedColor').getValue());
														}
														this.on('click', function(evt) {
															editor.openDialog('colordialog', function() {
																this.on ('ok', onColorSelect);
															});
														});													},											
													hidden : false,
													label : 'Select...'
												}

											]
										},
										// End Toolbar Text Color										

										// Toolbar Text Rollover Color
										{
											type: 'hbox',
											widths: [ '200px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'lightcolor',
													type : 'text',
													//style: 'width:95px;',
													label : 'Toolbar Text Rollover Color',
													labelLayout: 'horizontal',
													required : false
												},
												{
													type : 'button',
													id : 'btnlightcolor',
													onLoad : function()
													{
														function onColorSelect(evt) {
															this.removeListener('ok', onColorSelect);
															dlg.setValueOf('info', 'lightcolor', this.getContentElement('picker', 'selectedColor').getValue());
														}
														this.on('click', function(evt) {
															editor.openDialog('colordialog', function() {
																this.on ('ok', onColorSelect);
															});
														});
													},											
													hidden : false,
													label : 'Select...'
												}

											]
										},
										// End Toolbar Text Rollover Color										

										// Display Navigation
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'shownavigation',
													type : 'checkbox',
													label : 'Display Navigation',
													'default': 'checked',
													required : false
												}
											]
										},

										// Display Time
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'showdigits',
													type : 'checkbox',
													label : 'Display Time',
													'default': 'checked',
													required : false
												}
											]
										},

										// Align
										{
											type: 'hbox',
											widths: [ '100px', '50px' ],
											align: 'right',
											children:
											[
				
												{
													id : 'align',
													type : 'select',
													label : 'Align',
													labelLayout: 'horizontal',
													'default' : '',
													style : 'width : 100%;',
													items :
													[
														[ 'Left' , 'left'],
														[ 'Center', 'center' ],
														[ 'Right', 'right' ]
													]
												}
											]
										}
										// End Align
										

									]
								}
								// End Player Attributes
							 
							]
						} // End Movie Attributes and Player Attributes

					]
				}
			] // End contents
			
		}; // End return
		
	} ); // End CKEDITOR.dialog.add
	
})(); // End function()
